function add0(m){return m<10?'0'+m:m }
function format(shijianchuo)
{
//shijianchuo是整数，否则要parseInt转换
var time = new Date(shijianchuo);
var y = time.getFullYear();
var m = time.getMonth()+1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}
var rootPath = getRootPath();
$(document).ready(function(){
	
	var askingPriceId = getQueryParamValue("askingPriceId");
	$("#askingPriceId").val(askingPriceId);
	
	
	$.ajax({
		method : 'get',
		url : rootPath+'/wechat/api/askingPrice/'+askingPriceId,
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("连接服务器错误!");
		},
		success : function(resultData){
			
			var wholeHtml = '';
			
			$.each(resultData,function(askingpriceIndex,askingpriceObj){
				
				var askingpriceHtml = '';
				if(askingpriceObj.colorId=="-1"){
					askingpriceObj.colorId =" ";
				}
				if(askingpriceObj.status=="已报价"){
					
					askingpriceHtml = askingpriceHtml + '<div class="panel panel-default">'
					  								  +   '<ul class="list-group">'
					  								  +     '<li class="list-group-item">询价车型：'+askingpriceObj.modelName+'</li>'
					  								  +		'<li class="list-group-item">'
					  								  +		  '<span style="float:left">车型颜色：</span><div style="float:left;width:30px;height:20px;background-color:#'+ askingpriceObj.colorValue +'"></div><br><br>'
					  								  +		  '联&nbsp;&nbsp;系&nbsp;&nbsp;人：<span style="color:#787878">'+askingpriceObj.personalName+'</span><br><br>'
					  								  +		  '手机号码：<span style="color:#787878">'+askingpriceObj.phone+'</span><br><br>'
					  								  +		  '询价时间：<span style="color:#787878">'+format(askingpriceObj.askingPriceDate)+'</span><br>'
					  								  +		 '</li>'
					  								  +    '</ul>'
					  								  + '</div>'
					  								  + '<div class="panel panel-default">'
					  								  +   '<ul class="list-group">'
					  								  +     '<li class="list-group-item">'
					  								  +		  '询价状态：<span style="font-family:黑体;color:#48ACED">'+ askingpriceObj.status +'</span><br><br>'
					  								  +		  '销售报价：<br><span style="color:#48ACED;word-wrap:break-word;">'+ askingpriceObj.quoteContent +'</span><br><br>'
					  								  +		'</li>'
					  								  +    '</ul>'
					  								  + '</div>'
				}
				else if(askingpriceObj.status=="待报价"){
					
					askingpriceHtml = askingpriceHtml + '<div class="panel panel-default">'
													  +   '<ul class="list-group">'
													  +     '<li class="list-group-item">询价车型：'+askingpriceObj.modelName+'</li>'
													  +		'<li class="list-group-item">'
													  +		  '<span style="float:left">车型颜色：</span><div style="float:left;width:30px;height:20px;background-color:#'+ askingpriceObj.colorValue +'"></div><br><br>'
													  +		  '联&nbsp;系&nbsp;人：<span style="color:#787878">'+askingpriceObj.personalName+'</span><br><br>'
													  +		  '手机号码：<span style="color:#787878">'+askingpriceObj.phone+'</span><br><br>'
													  +		  '询价时间：<span style="color:#787878">'+format(askingpriceObj.askingPriceDate)+'</span><br>'
													  +		 '</li>'
													  +    '</ul>'
													  + '</div>'
													  + '<div class="panel panel-default">'
													  +   '<ul class="list-group">'
													  +     '<li class="list-group-item">'
													  +		  '询价状态：<span style="font-family:黑体;color:#F6304F">'+askingpriceObj.status+'</span><br><br>'
													  +		  '<small style="color:#B7B7B7">我们将以最快速度为您安排，请稍作等候。</small><br><br>'
													  +		'</li>'
													  +    '</ul>'
													  + '</div>'
													  + '<div class="panel panel-default">'
													  +   '<input style="background-color:#D2D2D2;color:white" type="button" data-toggle="modal" data-target="#myModal"  value="取消询价" class="btn btn-default btn-lg btn-block" />'
													  + '</div>'
				}
				else{
					
					askingpriceHtml = askingpriceHtml + '<div class="panel panel-default clearfix">'
					  								  +   '<ul class="list-group">'
					  								  +     '<li class="list-group-item">询价车型：'+askingpriceObj.modelName+'</li>'
					  								  +		'<li class="list-group-item">'
					  								  +		  '<span style="float:left">车型颜色：</span><div style="float:left;width:30px;height:20px;background-color:#'+ askingpriceObj.colorValue +'"></div><br><br>'
					  								  +		  '联&nbsp;系&nbsp;人：<span style="color:#787878">'+askingpriceObj.personalName+'</span><br><br>'
					  								  +		  '手机号码：<span style="color:#787878">'+askingpriceObj.phone+'</span><br><br>'
					  								  +		  '询价时间：<span style="color:#787878">'+format(askingpriceObj.askingPriceDate)+'</span><br>'
					  								  +		 '</li>'
					  								  +    '</ul>'
					  								  + '</div>'
					  								  + '<div class="panel panel-default">'
					  								  +   '<ul class="list-group">'
					  								  +     '<li class="list-group-item">'
					  								  +		  '询价状态：<span style="font-family:黑体;color:#C0C0C0">'+askingpriceObj.status+'</span>'
					  								  +		'</li>'
					  								  +    '</ul>'
					  								  + '</div>'
				}				  
				
				wholeHtml += askingpriceHtml;
			});
			
			$("#information").append(wholeHtml);
		}
	});
	
	$('#modalSure').click(function(){
		var data={
		askingPriceStatus:"",
		askingPriceId:"",
		updateDate:"",
    }; 
    data.askingPriceId = $.trim($("#askingPriceId").val()); 
    data.askingPriceStatus = $.trim($("#askingPriceStatus").val());
    var myDate = new Date();
    var result=myDate.getFullYear()+'-'+(myDate.getMonth()+1)+'-'+myDate.getDate() ;
    data.updateDate = myDate.getFullYear()+'-'+(myDate.getMonth()+1)+'-'+myDate.getDate()+' '+myDate.getHours()+':'+myDate.getMinutes() ;
   
	$.ajax({
		type : 'POST',
		url : rootPath+'/wechat/api/askingPrice/updateStatus',
		contentType:"application/json",
		data: JSON.stringify(data),
		error:function(XMLHttpRequest, ajaxOptions, thrownError){
			alert("失败");
		},
		success : function(data){
			$('#askingPriceModal').modal({
				keyboard: false,
				backdrop:false
			});
		}
	});
  });
})

function re(){
	window.location = rootPath + "/views/hp.html";
}